/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javafeiq.service.detect;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafeiq.service.detect.util.DetectService;
import javafeiq.service.detect.util.impl.UdpDetect;

/**
 *
 * @author bitray
 */
public class ClientDetectUtil {

    public List<String> getClientList() {
        List<String> returnList = new ArrayList<String>();
        try {
            InetAddress address = InetAddress.getLocalHost();
            String localIp = address.getHostAddress();
            String[] ipArray = localIp.split("\\.");
            if (ipArray.length == 4) {
                for (int i = 0; i < 256; i++) {
                    StringBuilder stringBuilder = new StringBuilder(ipArray[0]);
                    stringBuilder.append(".");
                    stringBuilder.append(ipArray[1]);
                    stringBuilder.append(".");
                    stringBuilder.append(ipArray[2]);
                    stringBuilder.append(".");
                    stringBuilder.append(i);
                    DetectService detectService=new UdpDetect();
                    boolean t = detectService.isConnect(stringBuilder.toString());
                    if (t) {
                        returnList.add(stringBuilder.toString());
                    }
                }
            }
        } catch (UnknownHostException ex) {
            Logger.getLogger(ClientDetectUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        return returnList;
    }


   
}
